﻿package com.starnet.sql;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

import com.starnet.constant.DataBaseConst;
import com.starnet.constant.DataListTable;

/**
 * 数据库操作
 * 
 * @author zmp
 * 
 */
public class SqliteOpenHelperClass extends SQLiteOpenHelper
{
 
	public SqliteOpenHelperClass(Context context)
	{
		super(context, DataBaseConst.DATABASE_NAME, null, DataBaseConst.DATABASE_VERSION);
	}

	@Override
	public void onCreate(SQLiteDatabase db)
	{
		// 创建表
		 db.execSQL(DataListTable.CREATE_DATALIST_TABLE);
	}

	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion)
	{
		db.execSQL(DataListTable.DELETE_DATALIST_TABLE);
		onCreate(db);
	}

	private static SqliteOpenHelperClass sqliteOpenHelperClass;

	/**
	 * 操作数据库的入口
	 * 
	 * @return
	 */
	public static SqliteOpenHelperClass getInstance(Context context)
	{
		if (sqliteOpenHelperClass == null) 
		{
			sqliteOpenHelperClass = new SqliteOpenHelperClass(context);
		}

		return sqliteOpenHelperClass;
	}


}
